local M = {}

function M.config()
  local npairs = require("nvim-autopairs")
  npairs.setup({
    check_ts = true,  -- 启用 treesitter 检查
    ts_config = {
      lua = { "string" }, -- 不在 lua 字符串中自动补全
      javascript = { "template_string" }, -- 不在模板字符串中自动补全
    },
    disable_filetype = { "TelescopePrompt", "vim" },
    fast_wrap = {
      map = "<M-e>",  -- Alt-e 快速包裹
      chars = { "{", "[", "(", '"', "'" },
      pattern = string.gsub([[ [%'%"%)%>%]%)%}%,] ]], "%s+", ""),
      offset = 0,
      end_key = "$",
      keys = "qwertyuiopzxcvbnmasdfghjkl",
      check_comma = true,
      highlight = "Search",
      highlight_grey = "Comment"
    },
  })

  -- 和 nvim-cmp 集成
  local cmp_autopairs = require('nvim-autopairs.completion.cmp')
  local cmp = require('cmp')
  cmp.event:on(
    'confirm_done',
    cmp_autopairs.on_confirm_done()
  )
end

return M
